package pruebas;


import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;

import org.openqa.selenium.*;
import org.openqa.selenium.htmlunit.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.ie.*;
import org.testng.annotations.*;

import static org.testng.Assert.*;

public class BusquedaGoogle {

	WebDriver driver;
	Selenium selenium;

	@BeforeMethod
	public void startSelenium() {
		driver = new FirefoxDriver();
		selenium = new WebDriverBackedSelenium(driver, "https://www.google.com.co/");
	}

	@AfterMethod
	public void stopSelenium() {
		driver.close();
	}

	@Test
	public void testJ()  {
		selenium.open("/?gws_rd=ssl");
		selenium.type("id=gbqfq", "selenium hq");
		selenium.click("id=gbqfb");
		for (int second = 0;; second++) {
			if (second >= 60) fail("timeout");
			 if (selenium.isElementPresent("link=Selenium - Web Browser Automation")) break; 
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		selenium.click("link=Selenium - Web Browser Automation");
		selenium.waitForPageToLoad("30000");
	}

}
